package ch01;

public class Cmd {
    private boolean helpFlag;   //是否是 help 查看帮助
    private boolean versionFlag;    //是否是查看版本
    private String cpOption;    //classPath 路径
    private String clazz;   //包含main方法的class文件
    private String[] args;    //参数
    private boolean isRight; //命令是否是正确的

    public Cmd(String[] args){
        parseCmd(args);
    }

    public void parseCmd(String[] args){
        //检验参数长度，起码得有一个，比如 java -version
        if(!(args.length>1)){
            isRight = false;
            return;
        }

        if ("-help".equals(args[1])||"-?".equals(args[1])){
            helpFlag = true;
        }else if("-version".equals(args[1])){
            versionFlag = true;
        }else if("-classPath".equals(args[1]) || "-cp".equals(args[1])){
            cpOption = args[1];
            clazz = args[2];
        }

        this.args = new String[args.length-1];
        for (int i=1;i< args.length;i++){
            this.args[i - 1] = args[i];
        }

        this.isRight = true;
    }

    public boolean isHelpFlag() {
        return helpFlag;
    }

    public void setHelpFlag(boolean helpFlag) {
        this.helpFlag = helpFlag;
    }

    public boolean isVersionFlag() {
        return versionFlag;
    }

    public void setVersionFlag(boolean versionFlag) {
        this.versionFlag = versionFlag;
    }

    public String getCpOption() {
        return cpOption;
    }

    public void setCpOption(String cpOption) {
        this.cpOption = cpOption;
    }

    public String getClazz() {
        return clazz;
    }

    public void setClazz(String clazz) {
        this.clazz = clazz;
    }

    public String[] getArgs() {
        return args;
    }

    public void setArgs(String[] args) {
        this.args = args;
    }

    public boolean isRight() {
        return isRight;
    }

    public void setRight(boolean right) {
        isRight = right;
    }
}
